﻿function createSNbox(theme){
    theme=(typeof theme!='undefined')?theme:'default';
    var css=document.createElement('link');
    css.href='/plugins/SNbox/theme/'+theme+'/style.css';
    css.rel="stylesheet";
    css.type="text/css";
    document.body.appendChild(css);
    var js=document.createElement('script');
    js.type='text/javascript';
    js.src='/plugins/SNbox/lib/fun.js';
    document.body.appendChild(js);
    var SNbox_overlay=document.createElement('div');
    SNbox_overlay.setAttribute('id','SNbox_overlay');
    document.body.appendChild(SNbox_overlay);
    var SNbox=document.createElement('div');
    SNbox.setAttribute('id','SNbox');
    document.body.appendChild(SNbox);
    document.getElementById('SNbox').innerHTML='<div id="SNbox_title" class ="SNbox_head_left" ><div class="SNbox_head_right"><div class="SNbox_head" id="SNbox_comment"></div></div></div>';
    document.getElementById('SNbox').innerHTML+='<div class="SNbox_close" onmousemove="this.style.backgroundImage=\'url(/plugins/SNbox/theme/'+theme+'/images/aero-close-over.gif)\'" onmouseout="this.style.backgroundImage=\'url(/plugins/SNbox/theme/'+theme+'/images/aero-close.gif)\'" onclick="box_remove();"></div><div id="SNbox_bg_left"><div id="SNbox_bg_right"><div  id="SNbox_bg_inner"></div></div></div>';
    var SNbox_data=document.getElementById('SNbox_data');
    document.getElementById('SNbox').innerHTML+='<div id="SNbox_content" class="SNbox_content">'+SNbox_data.innerHTML+'</div>';
    document.body.removeChild(SNbox_data)
 }
 
function box_show(box_title,box_width,box_height,box_id){
    if(getOS()=='MSIE'){
        document.body.style.cssText="height:100%;width:100%;overflow:hidden";
        if(document.getElementById("SNbox_HideSelect")===null){
            var ifr=document.createElement("iframe");
            ifr.setAttribute("id","SNbox_HideSelect");
            document.body.appendChild(ifr);
            $id('SNbox_HideSelect').style.display='block'
        }
        else 
            return
    }
    var ol=$id('SNbox_overlay');
    $event('add','click',box_remove,ol);
    box_position(box_width,box_height);
    $id('SNbox_comment').innerHTML=box_title;$id('SNbox_overlay').style.display='block';
    $id('SNbox').style.display='block';
    var SNbox_content=$id('SNbox_content');
    for(var i=0;i<SNbox_content.childNodes.length;i++){
        var c=SNbox_content.childNodes[i];
        if(c.id!=undefined)
            c.style.display='none'
        }
        $id(box_id).style.display='block'
    }
    
    function box_remove(){
        try{
            var ol=$id('SNbox_overlay');
            $event('remove','click',box_remove,ol);
            $id('SNbox').style.display='none';
            ol.style.display='none';
            if(getOS()=='MSIE'){
                var ifr=$id('SNbox_HideSelect');
                document.body.removeChild(ifr);
                document.body.style.cssText="height:auto;width:auto;overflow:auto"
            }
            return 
                false
        }
        catch(ex){}
    }
    
    function box_position(box_width,box_height){
        w=document.body.clientWidth;b=$id('SNbox').style;
        b.marginLeft='-'+parseInt((box_width/2),10)+'px';
        b.marginTop='-'+parseInt((box_height/2),10)+'px';
        b.width=box_width+'px';
        b.height=(box_height+18)+'px';
        if(getOS()=='MSIE'){
            b.position='absolute'
        }
        else{
            b.position='fixed'
        }
        
        b.zIndex='1000';
        b.top='280px';
        b.left=(w/2)+'px';
        $id('SNbox_overlay').style.width=w+'px';
        $id('SNbox_bg_inner').style.height=$id('SNbox_bg_right').style.height=$id('SNbox_bg_left').style.height=(box_height-9)+'px';
        $id('SNbox_bg_inner').style.width=(box_width-6)+'px';
        $id('SNbox_content').style.width=(box_width-12)+'px';
        $id('SNbox_content').style.height=(box_height-20)+'px'
    }
    
    
    
    
    
    function $id(){
        var objs;
        if(arguments.length==1){
            objs=document.getElementById(arguments[0]);
            if(!objs)
                objs=null
            }
            else{
                objs=[];
                for(var i=0;i<arguments.length;i++){
                    var obj=document.getElementById(arguments[i]);
                    if(obj)objs.push(obj)
                }
                if(objs.length<1)
                    objs=null
                }
                return objs
            }
            
   function $event(action,type,func,obj){
        if(!obj)obj=window;
        if(!type||!func)return;
        if(action=="add"){
            if(window.attachEvent){
                obj.attachEvent("on"+type,func)
            }
            else{
                obj.addEventListener(type,func,false)
            }
         }
         else{
            if(window.detachEvent){
                obj.detachEvent("on"+type,func)
            }
            else{
                obj.removeEventListener(type,func,false)
            }
         }
    }
    
    function getOS(){
        if(navigator.userAgent.indexOf("MSIE")>0){
            return"MSIE"}
        if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
            return"Firefox"}
        if(isSafari=navigator.userAgent.indexOf("Safari")>0){
            return"Safari"}
        if(isCamino=navigator.userAgent.indexOf("Camino")>0){
            return"Camino"}
        if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){
            return"Gecko"}
   }